#!/bin/bash
#backup_mysql db
#定义备份的变量
BAK_ADR=/date/backup/`date +%Y-%m-%d`
MYSQLDB=hanhan
MYSQLUSER=root
MYSQLPWD=12345678
MYSQLCMD=/usr/bin/mysqldump
if [ $UID -ne 0 ]; then
        echo "必须使用root账户使用此脚本"
        exit
fi

if [ ! -d $BAK_ADR ];then
        mkdir -p $BAK_ADR
        echo -e "\033[32mThe $BAK_DIR 创建目录成功!\033[0m"
else
        echo "此目录已经存在....."
fi
$MYSQLCMD -u$MYSQLUSER -p$MYSQLPWD $MYSQLDB >$BAK_ADR/$MYSQLDB.sql
if [ $? -eq 0 ];then
        echo -e "\033[32mThe Mysql Backup $MYSQLDB successfully!\033[0m"
        echo -e "\033[32mThe Mysql Backup $MYSQLDB Failed\033[0m"
fi

